
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link rel="stylesheet" href="css/style.css"/>

	<meta name="viewport" content="width=device-width, 
                                     initial-scale=1.0, 
                                     maximum-scale=1.0, 
                                     user-scalable=no">
	<!-- 引入jquery和bootstrap -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

<!-- <script src="js/homepageFunc.js"></script> -->

<title>搜索结果</title>
</head>

<body onload="getFlightInfo();">

	<!-- <div class="row">
		<div class="head">
			<img src="pic/homepage.png" alt="图标" class="imghead">
			<label for="" class="lbhead">&nbsp&nbsp&nbsp项&nbsp目&nbsp首&nbsp页</label>
		</div>
	</div> -->
	<div class="container">
		<!-- 导航栏 -->
		<nav class="navbar navbar-default" role="navigation">
		    <div class="container-fluid"> 
		    <div class="navbar-header">
		        <button type="button" class="navbar-toggle" data-toggle="collapse"
		                data-target="#example-navbar-collapse">
		            <span class="sr-only">切换导航</span>
		            <span class="icon-bar"></span>
		            <span class="icon-bar"></span>
		            <span class="icon-bar"></span>
		        </button>
		        <a class="navbar-brand" href="#">高性能民航旅客行程推荐系统</a>
		    </div>
		    <div class="collapse navbar-collapse" id="example-navbar-collapse">
		        <ul class="nav navbar-nav">
		            <li><a href="./index.html">返回主页</a></li>
		        </ul>
		    </div>
		    </div>
		</nav>

		<div>


			<div>
				<div class="row">
					<div class="col-md-1"></div>
					<div class="col-md-10">
						<div class="row"><h3>机票详情如下：</h3></div>

						<div class="row">
							<div class="box">
								<table class="table">
									<tr>
										<td>航班信息</td>
										<td>起飞时间</td>
										<td>到达时间</td>
										<td>航班号</td>
									</tr>
									<tr id="flightInfo">
										<!-- <td>
											<img src="pic/china.png" alt="中国国航" class="img2">
											<a href="#"> 中国国航&nbsp&nbsp&nbsp虹桥机场-大兴机场</a>
										</td>
										<td class="time">20:30</td>
										<td class="time">23:00</td>
										<td class="rate"><br>CU1234</td>
										<td class="price">
											￥372
											<button class="buybtn">立即抢</button>
										</td> -->
										
									</tr>
								</table>
							</div>
						</div>
					</div>
					
					</div>
				</div>
			</div>

			<table class="table table-striped">
			  <caption>机票信息</caption>
			  <thead>
			    <tr>
			      <th>机票类型</th>
			      <!-- <th>机票余量</th> -->
			      <th>机票价格</th>
			      <th>代理人</th>
			      <th>航班号</th>
			    </tr>
			  </thead>
			  <tbody id="result">

			  </tbody>
			</table>




	</div>
	
	
			


</body>
<script type="text/javascript">
	var $_GET = (function(){
    var url = window.document.location.href.toString();
	    var u = url.split("?");
	    if(typeof(u[1]) == "string"){
	        u = u[1].split("&");
	        var get = {};
	        for(var i in u){
	            var j = u[i].split("=");
	            get[j[0]] = j[1];
	        }
	        return get;
	    } else {
	        return {};
	    }
	})();

	console.log($_GET['flightId']);

</script>

<script type="text/javascript">
	function getFlightInfo(){
		// 获取航班信息
		var api = "./getFlightInfo";
		var flightId = $_GET['flightId'];
		var payload = "?flightId="+flightId;
		console.log(payload);
		$.get(api+payload, function(data,status){
		    	// alert("Data: " + data + "\nStatus: " + status);
		    	console.log(data);
		    	var row = data.split(",")[0].split("|");
		    	console.log(row);
		    	var head = row[7]+"&nbsp&nbsp&nbsp"+row[5]+"->"+row[6];
		    	var _html = "";

		    	console.log(_html);
		    	$("#result").html(_html);
		    	var info = '<td><img src="pic/china.png" alt="'+row[7]+'" class="img2"><a href="#">'+head+'</a></td><td class="time">'+row[1]+'</td><td class="time">'+row[2]+'</td><td class="rate"><br>'+row[0]+'</td>';
				$("#flightInfo").html(info);
				console.log(info);
				
				getTicket();
		});

		
	}
	function getTicket(){
		// 获取某航班机票信息
		var api = "./getTicket";
		var flightId = $_GET['flightId'];
		var payload = "?flightId="+flightId;
		console.log(payload);

		$.get(api+payload, function(data,status){
		    	// alert("Data: " + data + "\nStatus: " + status);
		    	console.log(data);
		    	var row = data.split(",");
		    	var _html = "";
		    	for (let i = 0; i < row.length; i ++){
		    		_html += "<tr>";
		    		var column = row[i].split("|");
		    		for (let j = 0; j < column.length; j ++){
		    			if (j == 1){
		    				_html += '<td class="price">￥'+column[j]+'<button class="buybtn" onclick="window.location.href=\'https://www.airchina.com.cn\'">立即抢</button></td>';
		    			}else{
		    				_html += "<td>"+column[j]+"</td>";
		    			}
		    		}
		    		_html += "</tr>";
		    	}
		    	console.log(_html);
		    	$("#result").html(_html);
		});

	}

</script>

<!-- 更改鼠标样式 -->
<script>
document.getElementsByTagName("html")[0].style.cursor = "url('https://blog-static.cnblogs.com/files/Mz1-rc/iicon.ico?t=1643181505'), default";
</script>

</html>
